package cn.stylefeng.guns.modular.api;

import cn.stylefeng.guns.api.core.util.JwtTokenUtil;
import cn.stylefeng.guns.modular.business.model.params.ReadMessageDTO;
import cn.stylefeng.guns.modular.business.service.ReadMessageService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


/**
 * 已读消息表控制器
 *
 * @author
 * @Date 2019-07-30 19:13:15
 */
@Controller
@RequestMapping("/gunsApi/readMessage")
public class ReadMessageApi extends BaseController {


    @Autowired
    private ReadMessageService readMessageService;

    /**
     * 新增接口
     *
     * @author
     * @Date 2019-07-30
     */
    @PostMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(@RequestBody ReadMessageDTO readMessageDTO) {
        this.readMessageService.add(readMessageDTO, readMessageDTO.getUserId());
        return ResponseData.success();
    }

    @PostMapping("/add-all-unread")
    @ResponseBody
    public ResponseData addAllUnreadItem(@RequestParam Long userId) {
        this.readMessageService.addAllUnreadItem(userId);
        return ResponseData.success();
    }

    /**
     * 查询所有未读消息数量
     *
     * @author
     * @Date 2019-09-15
     */
    @PostMapping("/unread-num")
    @ResponseBody
    public ResponseData unreadNum(@RequestParam Long userId) {
        return ResponseData.success(readMessageService.getUnReadNum(userId));
    }

}


